<?php
class ControllerExtensionModuleBlogLatest extends Controller {
	public function index() {
		if (!$this->config->get('blog_status')) {
			return;
		}

		$titles = $this->config->get('blog_latest_title');
		if (isset($titles[$this->config->get('config_language_id')])) {
			$data['heading_title'] = $titles[$this->config->get('config_language_id')];
		} else {
			$data['heading_title'] = '';
		}

		$this->load->model('blog/blog');

		$data['posts'] = array();
		$posts = $this->model_blog_blog->getLatestPosts($this->config->get('blog_latest_limit'));
		foreach ($posts as $post) {
			$data['posts'][] = array(
				'name'       => $post['name'],
				'date_added' => date($this->language->get('date_format_short'), strtotime($post['date_added'])),
				'href'       => $this->url->link('blog/post', "blog_post_id={$post['post_id']}")
			);
		}

		if ($data['posts']) {
			return $this->load->view('extension/module/blog_latest', $data);
		}
	}
}
